#include <iostream>
#include <memory>

class CashSuper
{
public:
    using ptr = std::shared_ptr<CashSuper>;
    virtual double getResult(double money) = 0;
};

class CashNormal : public CashSuper
{
public:
    using ptr = std::shared_ptr<CashNormal>;
    virtual double getResult(double money) override
    {
        return money;
    }
};

class CashRebate : public CashSuper
{
public:
    using ptr = std::shared_ptr<CashRebate>;
    CashRebate(double rebate) : m_rebate(rebate) {}
    virtual double getResult(double money) override
    {
        return money * m_rebate;
    }

private:
    double m_rebate;
};

class CashReturn : public CashSuper
{
public:
    using ptr = std::shared_ptr<CashReturn>;
    CashReturn(double boundary, double v_return):m_boundary(boundary),m_return(v_return){}
    virtual double getResult(double money) override
    {
        return money - (int)money / (int)m_boundary * m_return;
    }

private:
    double m_boundary;
    double m_return;
};

//具体的策略类，策略管理类，用于配置不同的测率
class CashContext
{
public:
    CashContext(CashSuper::ptr cashStrategy):m_cashStrategy(cashStrategy){}
    void setStratery(CashSuper::ptr cashStrategy){m_cashStrategy=cashStrategy;}
    CashSuper::ptr getStratery(){return m_cashStrategy;}
    double getResult(double money) {
        return m_cashStrategy->getResult(money);
    }
private:
    CashSuper::ptr m_cashStrategy;
};

int main(int argc, char** argv)
{
    CashSuper::ptr cs(new CashReturn(300,10));
    CashSuper::ptr cr(new CashRebate(0.8));
    std::cout<<"满300减10的结果:"<<std::endl;
    std::cout<<CashContext(cs).getResult(890.6)<<std::endl;
    std::cout<<"打八折的结果:"<<std::endl;
    std::cout<<CashContext(cr).getResult(890.6)<<std::endl;
    return 0;
}